/**
 * Author(s): xuming.Wong <xuming.Wong@gmail.com>
 */
#include "TerrainLayerControl.h"

#include <QtGui/QMouseEvent>
#include <QtGui/QIcon>


#include "GPKFile.h"

namespace PQBuilder
{
	TerrainLayerControl::TerrainLayerControl(QWidget* parent)
		: QListWidget(parent)
	{
		this->setViewMode(QListView::IconMode);
		this->setGridSize(QSize(GRID_SIZE_X, GRID_SIZE_Y));
		this->setFlow(QListView::LeftToRight);
		this->setIconSize(QSize(ICON_SIZE, ICON_SIZE));
		this->setDragDropMode(QAbstractItemView::NoDragDrop);
		
		loadLayer();

		connect(this,SIGNAL(itemClicked(QListWidgetItem*)),this,SLOT(OnItemClicked(QListWidgetItem*)));
	}

	void TerrainLayerControl::addTerrainTextureLayer(const QString& name)
	{
		assert(false);

		/*
		PQEngine::GPKFile* file=SEngine.getTerrainTextureFile(name.toStdString());
		if(!file||!file->ok()){
			return;
		}

		file->open();
		int len=file->length();
		char* buf=new char[len];
		file->read(buf,len);
		file->close();

		QString text=QObject::tr("Layer");
		QString num;
		text+= num.setNum(_textureNameList.size());

		
		QByteArray bytes(buf,len);
		QImage image;
		image.loadFromData(bytes);
		QPixmap pixmap=QPixmap::fromImage(image);
		
		QListWidgetItem *item=new QListWidgetItem(QIcon(pixmap),text);
		item->setWhatsThis(name);
		item->setToolTip(name);
		this->addItem(item);

		
		_textureNameList.push_back(name);

		SEngine.addTerrainLayer(name.toStdString());
		*/
	}

	void TerrainLayerControl::OnItemClicked(QListWidgetItem* item)
	{
		int row=this->row(item);
		assert(false);
		/*
		SEngine.selectTerrainLayer(row);
		*/
	}

	void TerrainLayerControl::loadLayer()
	{
		
	}


}
